package com.ordertracker.security;

import com.ordertracker.Application;
import com.ordertracker.Session;
import com.ordertracker.persistent.dictionary.Role;
import com.ordertracker.persistent.dictionary.User;

import javax.ws.rs.core.SecurityContext;
import java.security.Principal;

/**
 * Description of class.
 * Created 1/9/13 3:28 PM
 *
 * @author andrey.rodin@playtech.com
 */

public class ApplicationSecurityContext implements SecurityContext{

    private final User user;
    private final Session session;

    public ApplicationSecurityContext(Session session) {
        this.user = session.getUser();
        this.session = session;
    }

    @Override
    public Principal getUserPrincipal() {
        return user;
    }

    @Override
    public boolean isUserInRole(String role) {
        System.out.println(role);
        return true;
    }

    @Override
    public boolean isSecure() {
        return (null != session) ? session.isSecure() : false;
    }

    @Override
    public String getAuthenticationScheme() {
        return Application.getApplication().getConfig().getAuthorizationType();
    }

    public Session getSession() {
        return session;
    }
}
